<!-- 保证金 -->
<template>
	<view class="content">
		<view class="content-title"> </view>
		<view class="content-box">
			<text>{{ensureAccount}}</text>
			<text>保证金金额(元)</text>
			<view :class="[ensureAccount==0?'active1':'active2']" @click="openFudai "> 缴纳保证金 </view>
			<view :class="[ensureAccount==0?'active2':'active22']" @click="onOpenMost"> 退还保证金 </view>
		</view>
		<view class="content-rule">
			<text>保证金规则</text>
			<view>
				<image class="img" src="https://images.linglinggong.net/static/icon3/earnest/icon1.png" mode=""></image>
				保证金金额
			</view>
			<view class="">
				<text></text>
				<text>首次缴纳 200元 保证金;</text>
			</view>
			<view class="">
				<text></text>
				<text>二次缴纳 300元 保证金;</text>
			</view>
			<view class="">
				<text></text>
				<text>三次及以上缴纳 500元 保证金;</text>
			</view>
			<view>
				<image class="img" src="https://images.linglinggong.net/static/icon3/earnest/icon2.png" mode=""></image>
				保证金作用
			</view>
			<text>缴纳保证金是为了保障金牌零工的工作规范及相关权益;</text>
			<view>
				<image class="img" src="https://images.linglinggong.net/static/icon3/earnest/icon3.png" mode=""></image>
				保证金退款
			</view>
			<view>
				<view> 金牌零工晋升期间，保证金不可退还；</view>
				<view> 金牌零工保留期间，保证金<text>请不要退还</text>，否则 <text>会失去金牌零工身份</text>；</view>
			</view>
			<view>
				<image class="img" src="https://images.linglinggong.net/static/icon3/earnest/icon2.png" mode=""></image>
				保证金扣除
			</view>
			<text> 目前保证金不会被扣除； </text>
		</view>
		<!-- 缴纳保证金 -->
		<u-popup round=24 :show="showPopup" mode="bottom" @close="showPopup=false">
			<view class="popupContent">
				<view class="popupContent-title"> 缴纳保证金 <image @click="closePop" class="img"
						src="https://images.linglinggong.net/static/icon3/earnest/close.png" mode=""></image>
				</view>
				<view class="popupContent-content">
					<text>
						缴纳{{([0,1].includes(ensureAccountCount)&&200)||(ensureAccountCount==2&&300)||(ensureAccountCount>=3&&500)}}元保证金晋升金牌
					</text>
					<text> 立即享受金牌权益 </text>
				</view>
				<view class="popupContent-btn" @click="toPay">确认</view>
			</view>
		</u-popup>
		<!-- 退还保证金 -->
		<mosk v-if="showMosk" :ensureAccount='ensureAccount' @close='close'></mosk>
		<!-- 		<Pay v-if="isOpenModal"
			:price='([0,1].includes(ensureAccountCount)&&200)||(ensureAccountCount==2&&300)||(ensureAccountCount>=3&&500)'
			@close='close'>
		</Pay> -->
		<ChangePay @closePayPage='closePayPage' v-if="isOpenModal" title='保证金'
			:monery='([0,1].includes(ensureAccountCount)&&200)||(ensureAccountCount==2&&300)||(ensureAccountCount>=3&&500)'
			:url="`/t/user/payEnsureAccount`" keyWorld='account' @paySuccess='paySuccess'>
		</ChangePay>
	</view>
</template>
<script>
	import mosk from './components/mosk.vue'
	import Pay from './components/pay.vue'
	export default ({
		components: {
			mosk,
			Pay,
		},
		data() {
			return {
				isOpenModal: false, //支付
				showMosk: false, //是否退还
				showPopup: false, //缴纳保证金
				ensureAccount: 0, //保证金
				ensureAccountCount: 0, //保证金缴纳次数
				changeWay: false, //支付方式
			}
		},
		onload() {},
		methods: {
			//关闭支付方式
			closePayPage() {
				this.isOpenModal = false
				this.getUser()
			},
			paySuccess() {
				this.isOpenModal = false
				this.getUser()
			},
			// 获取用户信息
			async getUser() {
				let res = await this.$fetch(this.$api.get_user_by_id, {}, 'POST')
				let {
					ensureAccount,
					ensureAccountCount
				} = res.data
				this.ensureAccount = ensureAccount || 0
				this.ensureAccountCount = ensureAccountCount + 1
			},
			// 开启缴纳
			openFudai() {
				if (this.ensureAccount == 0) {
					this.showPopup = true
				}
			},
			// 缴纳保证金
			toPay() {
				this.isOpenModal = true
				this.showPopup = false
			},
			// 关闭弹框
			closePop() {
				this.showPopup = false
				this.isOpenModal = false
			},
			// 开启退还弹框
			onOpenMost() {
				if (parseFloat(this.ensureAccount) <= 0) return
				this.showMosk = true
			},
			//关闭 提现
			close(e) {
				this.isOpenModal = false
				if (e == 1) {
					this.$fetch(this.$api.refundEnsureAccount, 'GET').then(res => {
						if (res.code == 0) {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
						} else {
							this.getUser()
						}
					})
				}
				this.showMosk = false
				this.getUser()
			}
		},
		onShow() {
			this.getUser()
			this.isOpenModal = false
		},
		onNavigationBarButtonTap(e) {
			uni.navigateTo({
				url: '/pages/earnestDetail/earnestDetail'
			})
		},
		onShareAppMessage() {
			return {
				title: "在家找日结兼职，工种齐全",
				desc: "免费使用，提前在家找日结兼职",
				path: `/pages/start-n/start-n`,
				imageUrl: 'https://images.linglinggong.net/static/employee-share.jpg',
				success: res => {}
			}
		},
	})
</script>
<style lang="scss" scoped>
	.content {
		width: 100vw;
		min-height: 100vh;
		background: #F1F1F5;

		&-title {
			width: 100%;
			height: 264rpx;
			background: url('https://images.linglinggong.net/XCX/top-bg.png') center center/cover no-repeat;
		}

		&-box {
			width: 694rpx;
			height: 610rpx;
			background: #FFFFFF;
			box-shadow: 0px 6rpx 24rpx 2rpx rgba(171, 173, 177, 0.16);
			border-radius: 24rpx;
			opacity: 1;
			display: flex;
			justify-content: center;
			flex-direction: column;
			overflow: hidden;
			align-items: center;
			margin: -216rpx auto 0;

			&>text:nth-child(1) {
				text-align: center;
				font-size: 104rpx;
				font-weight: 800;
				color: #262626;
				margin-top: 70rpx;
				height: 146rpx;
				line-height: 146rpx;
			}

			&>text:nth-child(2) {
				text-align: center;
				font-size: 28rpx;
				font-weight: 400;
				color: #262626;
				margin-bottom: 40rpx;
			}

			&>view:nth-child(3) {
				width: 566rpx;
				height: 88rpx;
				border-radius: 12rpx;
				opacity: 1;
				margin-bottom: 40rpx;
				font-size: 32rpx;
				text-align: center;
				line-height: 88rpx;
			}

			.active1 {
				background: #FCC928;
				color: #262626;
				box-shadow: 0px 6rpx 12rpx 2rpx rgba(252, 201, 40, 0.4);
			}

			.active22 {
				// background: #FCC928;
				// color: #262626;
				// box-shadow: 0px 6rpx 12rpx 2rpx rgba(252, 201, 40, 0.4);
				border-radius: 12rpx;
				border: 2rpx solid #7F7F7F;
			}

			.active2 {
				background: #E7E7EB;
				border: 2rpx solid #E7E7EB;
				color: #BDBDBD;
			}

			&>view:nth-child(4) {
				width: 566rpx;
				height: 88rpx;
				border-radius: 12rpx;
				opacity: 1;
				font-size: 32rpx;
				text-align: center;
				line-height: 88rpx;
			}
		}

		&-rule {
			margin: 80rpx 0 24rpx 28rpx;

			&>text:nth-child(1) {
				font-size: 32rpx;
				font-weight: bold;
				color: #262626;
				display: flex;
				padding-bottom: 40rpx;
			}

			&>view:nth-child(2) {
				font-size: 32rpx;
				color: #262626;
				display: flex;
				align-items: center;
				margin-bottom: 20rpx;
			}

			&>view:nth-child(3),
			&>view:nth-child(4),
			&>view:nth-child(5) {
				margin-bottom: 20rpx;
				display: flex;
				color: #515151;
				font-size: 28rpx;
				display: flex;
				align-items: center;

				&>text:nth-child(1) {
					display: block;
					width: 8rpx;
					height: 8rpx;
					background: #262626;
					border-radius: 50%;
					margin-right: 20rpx;
				}

				&>text:nth-child(2) {
					font-size: 28rpx;
					color: #515151;
				}
			}

			&>view:nth-child(5) {
				margin-bottom: 40rpx;
			}

			&>view:nth-child(6) {
				font-size: 32rpx;
				color: #262626;
				display: flex;
				align-items: center;
				margin-bottom: 20rpx;
			}

			&>text:nth-child(7) {
				font-size: 28rpx;
				font-weight: 400;
				color: #515151;
				display: flex;
				margin-bottom: 40rpx;
			}

			&>view:nth-child(8) {
				font-size: 32rpx;
				color: #262626;
				display: flex;
				align-items: center;
				margin-bottom: 20rpx;
			}

			&>view:nth-child(9) {
				font-size: 28rpx;
				font-weight: 400;
				color: #515151;
				display: flex;
				margin-bottom: 40rpx;
				flex-direction: column;
				line-height: 1.5;

				&>view:nth-child(2) {
					&>text:first-child {
						font-weight: bold;
						color: #262626;
					}

					&>text:last-child {
						font-weight: bold;
						color: #F85A41;
					}
				}
			}

			&>view:nth-child(10) {
				font-size: 32rpx;
				color: #262626;
				display: flex;
				align-items: center;
				margin-bottom: 20rpx;
			}

			&>text:nth-child(11) {
				font-size: 28rpx;
				font-weight: 400;
				color: #515151;
			}
		}
	}

	.popupContent {
		padding-bottom: 72rpx;

		&-title {
			font-size: 40rpx;
			font-weight: 800;
			color: #262626;
			text-align: center;
			margin: 40rpx 0 88rpx;
			width: 100%;
			position: relative;

			.img {
				position: absolute;
				right: 0;
				float: right;
			}
		}

		&-content {
			text-align: center;
			margin-bottom: 74rpx;
			display: flex;
			flex-direction: column;
			line-height: 1.87;

			&>text:first-child {
				text-align: center;
				font-size: 32rpx;
				color: rgba(81, 81, 81, 1);
			}

			&>text:last-child {
				color: rgba(78, 153, 0, 1);
				text-align: center;
				font-size: 28rpx;
			}
		}

		&-btn {
			width: 694rpx;
			height: 88rpx;
			background: #FCC928;
			box-shadow: 0px 6rpx 12rpx 2rpx rgba(255, 133, 29, 0.3);
			border-radius: 12rpx;
			opacity: 1;
			margin: 0 auto;
			font-size: 36rpx;
			font-weight: bold;
			color: #333333;
			text-align: center;
			line-height: 88rpx;
		}
	}

	.img {
		width: 48rpx;
		height: 48rpx;
		margin-right: 10rpx;
	}
</style>